package org.mapwar.server.persistence.dao.impl;

import org.mapwar.server.persistence.common.ConfigId;
import org.mapwar.server.persistence.dao.UserDaoCustom;
import org.springframework.beans.factory.annotation.Qualifier;

import com.google.common.collect.Lists;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhebinwang on 2017/9/27.
 */
@Repository
public class UserDaoCustomImpl implements UserDaoCustom {
    @PersistenceContext(unitName = "backendPU")
    @Qualifier(value = "backendEntityManagerFactory")
    private EntityManager entityManager;


    public int getTestSqlResult(){
        String sql="select id,config_name from t_link_config";
        Query query = entityManager.createNativeQuery(sql.toString());

        //Query query = entityManager.createNativeQuery(sql.toString());
        //query.setParameter("unitid", unitId);
        List<ConfigId> userResponses = Lists.newArrayList();
        List<Object[]> records = query.getResultList();
        Iterator<Object[]> iterator = records.iterator();
        int f=records.size();
        while (iterator.hasNext()) {
            Object[] result = iterator.next();
            //ConfigId ranking = extractRankingVo(result);
            //userResponses.add(ranking);
        }
        return f;

    }

}
